package com.homwee.factory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;


public class FactorySelDialog extends Dialog{
	public static String mPath1 ="/hwcfg/product/";
	public static String mPath2 ="/vendor/tvconfig/config/panel/";
	public static String mPath3 ="/perm/chmw/tuner_cfg/";
	public static String mPath4 ="/chperm/chmw/tuner_cfg/";
	private Context mContext;

	private ListView mListView;
	private String mSelName =null;
	private List<String> mDatas =new ArrayList<String>();
	private String mPath =mPath1;
	
	String mProductSize =null;

	private static String[] panelStrings={
		"40_SAMSUNG_FHD_100_120",          "HDMITX_1440_60P",                    
		"AU20_T200XW02",                   "HDMITX_1470_60P",                    
		"AU32_T315XW03",                   "HDMITX_2160_24P",                    
		"AUO_T420HW09_TCON",               "HDMITX_480_60P",                     
		"DACOUT_1080I_50",                 "HDMITX_4K1K_60P",                    
		"DACOUT_1080I_60",                 "HDMITX_4K2K_25P",                    
		"DACOUT_1080P_24",                 "HDMITX_4K2K_30P",                    
		"DACOUT_1080P_25",                 "HDMITX_576_50P",                     
		"DACOUT_1080P_30",                "HDMITX_720_50P",                     
		"DACOUT_1080P_50",                "HDMITX_720_60P",                     
		"DACOUT_1080P_60",                "HDMITX_VB1_1080_60P",                
		"DACOUT_2205P_24",                 "HDMITX_VB1_4K2K_30P",                
		"DACOUT_4096X2160P_24",            "HDMITX_VB1_4K2K_60P",                
		"DACOUT_4096X2160P_25",            "M190A1",                             
		"DACOUT_4096X2160P_30",            "Panel",                              
		"DACOUT_4096X2160P_50",            "SXGA_AU17_EN05",                     
		"DACOUT_4096X2160P_60",            "UD_4K2K_Vx1_4lane",                  
		"DACOUT_480I_60",                  "UD_CMO4K1K_HSLVDS_10bit_Bypass",     
		"DACOUT_480P_60",                  "UD_CMO4K1K_NikeU",                   
		"DACOUT_4K2KP_24",                 "UD_CMO4K1K_URSA",                    
		"DACOUT_4K2KP_25",                 "UD_CMO4K2K_Bypass",                  
		"DACOUT_4K2KP_30",                 "UD_CMO4K2K_FRC",                     
		"DACOUT_4K2KP_50",                 "UD_CMO4K2K_HSLVDS",                  
		"DACOUT_4K2KP_60",                 "UD_CMO4K2K_HSLVDS_10bit_Bypass",     
		"DACOUT_576I_50",                  "UD_CMO4K2K_INX_VB1",                 
		"DACOUT_576P_50",                  "UD_CMO4K2K_NikeU",                   
		"DACOUT_720P_50",                  "UD_CMO4K2K_URSA",                    
		"DACOUT_720P_60",                  "UD_VB1_16LANE",                      
		"FHD_2K1K_Vx1_2lane",              "UD_VB1_16LANE_CSOT_URSA",            
		"FullHD_CMO216_H1L01",             "UD_VB1_2V",                          
		"FullHD_CMO216_H1L01_720P",        "UD_VB1_2V2O",                        
		"FullHD_CMO216_H1L01_HSLVDS",      "UD_VB1_4LANE",                       
		"FullHD_CMO216_H1L01_NikeU",       "UD_VB1_4V",                          
		"FullHD_CMO216_H1L01_Rocket",      "UD_VB1_4V2O",                        
		"FullHD_CMO216_H1L01_URSA",        "UD_VB1_8LANE",                       
		"FullHD_CMO216_H1L01_auto_test",   "UD_VB1_8LANE_CSOT",                  
		"FullHD_LG120HZ",                  "UD_VB1_8LANE_CSOT_120",              
		"FullHD_LG420EUF_120HZ_3DPASSIVE", "UD_VB1_8LANE_CSOT_240",              
		"FullHD_VB1_2LANE",                "UD_VB1_8LANE_CSOT_URSA",             
		"FullHD_VB1_4LANE",                "UD_VB1_8LANE_CSOT_URSA_PWM_INVERSE", 
		"HDMITX_1080_50I",                 "UD_VB1_8LANE_FHD",                   
		"HDMITX_1080_50P",                 "UD_VB1_8LANE_ISP",                   
		"HDMITX_1080_60I",                 "UD_VB1_8LANE_M28DGJ_L30",            
		"HDMITX_1080_60P",                 "WXGA_LG32_LC320EXN",                 
		"HDMITX_1440_50P"};

	public FactorySelDialog(Context context) {
    	super(context, R.style.Theme_FactorySettingDialog);
    	mContext =context;
    	setFilePath(mPath1);
    	setContentView(R.layout.menu_sel_list);
    	mListView =(ListView) findViewById(R.id.listView1);
    	mListView.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_expandable_list_item_1,mDatas));
    	mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				mSelName = ((TextView)arg1).getText().toString();
				cancel();
			}
		});
    	
    	mListView.setSelector(R.drawable.settings_item_selector);
	}
	
	
    private void initData(){
    	File mFileDrect= new File(mPath);
    	Log.v("zcj","mPath="+ mPath+"mFileDrect="+mFileDrect.getAbsolutePath());
    	File [] mFiles;
    	mDatas.clear();
    	
    	if(mFileDrect.exists() &&mFileDrect.isDirectory()){
    		//mFiles =mFileDrect.listFiles();
    		//Log.v("zcj","mFiles="+ mFiles.length);
    		//if(mFiles !=null){
        		for(int i=0;i<panelStrings.length;i++){
        			String name =panelStrings[i];
        			Log.v("zcj","add name ="+ name);
        			/*if(name.endsWith(".ini")){
            			name =name.replace(".ini", "");*/
            			Log.v("zcj","add name ="+ name);
            			/*if(mProductSize ==null ||name.contains(mProductSize)){
            				Log.v("tv","add name ="+ name);*/
                			mDatas.add(name);
            			//}
        			//}
        		//}
    		}
    	}
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	// TODO Auto-generated method stub
    	return super.onKeyDown(keyCode, event);
    }
    
    public void setFilePath(String path){
    	mPath =path;
    	initData();
    }
    
    public void setProductSize(String size){
    	Log.v("tv","size ="+size);
    	mProductSize =size;
    }
    
    public String getSelName(){
    	return mSelName;
    }
}

